<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>获取用户信息</title>
    <link rel="stylesheet" href="/public/system/plugins/layui/css/layui.css">
    <script src="/public/system/plugins/jquery-2.1.4.js"></script>
    <script src="/public/system/plugins/layui/layui.js"></script>
    <script>var _config = {$auth_config};</script>
    <script src="https://g.alicdn.com/dingding/dingtalk-pc-api/2.7.0/index.js"></script>
</head>
<body>
<script>
    DingTalkPC.config({
        agentId: _config.agentId,
        corpId: _config.corpId,
        timeStamp: _config.timeStamp,
        nonceStr: _config.nonceStr,
        signature: _config.signature,
        jsApiList: ['device.notification.alert','runtime.permission.requestAuthCode'] // 必填，需要使用的jsapi列表
    });
    DingTalkPC.ready(function(res){
        DingTalkPC.runtime.permission.requestAuthCode({
            corpId: _config.corpId,
            onSuccess: function(result) {
                $.ajax({
                    url: "{:url('auth')}",
                    type:"POST",
                    data: {"code":result.code},
                    dataType:'json',
                    async:false,
                    timeout: 900,
                    success: function (res, status, xhr) {
                        if (res.code === 1) {
                            location.href = "{:url('Index/index')}";
                        } else {
                            alert('获取用户信息错误: ' + res.msg);
                        }
                    },
                    error: function (xhr, errorType, error) {
                        alert(errorType + ', ' + error);
                    }
                });
            },
            onFail : function(err) {
                DingTalkPC.device.notification.alert({
                    message: JSON.stringify(err),
                    title: "提示",//可传空
                    buttonName: "确定"
                });
            }
        })
    });
</script>
</body>
</html>